package o;

import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.io.Closeable;
import java.io.Flushable;
import java.io.IOException;
import java.io.Writer;

public class aux implements Closeable, Flushable {
    private static final String[] ˏ = new String[DnsConfig.MAX_CACHE_ENTRIES];
    private static final String[] ॱ = ((String[]) ˏ.clone());
    private boolean ʻ;
    private String ʼ;
    private boolean ʽ;
    private int ˊ = 0;
    private final Writer ˋ;
    private boolean ˋॱ;
    private int[] ˎ = new int[32];
    private String ॱॱ;
    private String ᐝ;

    static {
        for (int i = 0; i <= 31; i++) {
            ˏ[i] = String.format("\\u%04x", new Object[]{Integer.valueOf(i)});
        }
        ˏ[34] = "\\\"";
        ˏ[92] = "\\\\";
        ˏ[9] = "\\t";
        ˏ[8] = "\\b";
        ˏ[10] = "\\n";
        ˏ[13] = "\\r";
        ˏ[12] = "\\f";
        ॱ[60] = "\\u003c";
        ॱ[62] = "\\u003e";
        ॱ[38] = "\\u0026";
        ॱ[61] = "\\u003d";
        ॱ[39] = "\\u0027";
    }

    public aux(Writer writer) {
        ˎ(6);
        this.ʼ = ":";
        this.ˋॱ = true;
        if (writer == null) {
            throw new NullPointerException("out == null");
        }
        this.ˋ = writer;
    }

    public final void ˋ(String str) {
        if (str.length() == 0) {
            this.ॱॱ = null;
            this.ʼ = ":";
            return;
        }
        this.ॱॱ = str;
        this.ʼ = ": ";
    }

    public final void ˋ(boolean z) {
        this.ʽ = z;
    }

    public boolean ॱॱ() {
        return this.ʽ;
    }

    public final void ˎ(boolean z) {
        this.ʻ = z;
    }

    public final boolean ʽ() {
        return this.ʻ;
    }

    public final void ॱ(boolean z) {
        this.ˋॱ = z;
    }

    public final boolean ʼ() {
        return this.ˋॱ;
    }

    public aux ˎ() throws IOException {
        ʻ();
        return ॱ(1, "[");
    }

    public aux ॱ() throws IOException {
        return ˋ(1, 2, "]");
    }

    public aux ˊ() throws IOException {
        ʻ();
        return ॱ(3, "{");
    }

    public aux ˏ() throws IOException {
        return ˋ(3, 5, "}");
    }

    private aux ॱ(int i, String str) throws IOException {
        ˋॱ();
        ˎ(i);
        this.ˋ.write(str);
        return this;
    }

    private aux ˋ(int i, int i2, String str) throws IOException {
        int ˋ = ˋ();
        if (ˋ != i2 && ˋ != i) {
            throw new IllegalStateException("Nesting problem.");
        } else if (this.ᐝ != null) {
            throw new IllegalStateException("Dangling name: " + this.ᐝ);
        } else {
            this.ˊ--;
            if (ˋ == i2) {
                ॱˊ();
            }
            this.ˋ.write(str);
            return this;
        }
    }

    private void ˎ(int i) {
        if (this.ˊ == this.ˎ.length) {
            Object obj = new int[(this.ˊ * 2)];
            System.arraycopy(this.ˎ, 0, obj, 0, this.ˊ);
            this.ˎ = obj;
        }
        int[] iArr = this.ˎ;
        int i2 = this.ˊ;
        this.ˊ = i2 + 1;
        iArr[i2] = i;
    }

    private int ˋ() {
        if (this.ˊ != 0) {
            return this.ˎ[this.ˊ - 1];
        }
        throw new IllegalStateException("JsonWriter is closed.");
    }

    private void ˊ(int i) {
        this.ˎ[this.ˊ - 1] = i;
    }

    public aux ॱ(String str) throws IOException {
        if (str == null) {
            throw new NullPointerException("name == null");
        } else if (this.ᐝ != null) {
            throw new IllegalStateException();
        } else if (this.ˊ == 0) {
            throw new IllegalStateException("JsonWriter is closed.");
        } else {
            this.ᐝ = str;
            return this;
        }
    }

    private void ʻ() throws IOException {
        if (this.ᐝ != null) {
            ˊॱ();
            ˏ(this.ᐝ);
            this.ᐝ = null;
        }
    }

    public aux ˊ(String str) throws IOException {
        if (str == null) {
            return ᐝ();
        }
        ʻ();
        ˋॱ();
        ˏ(str);
        return this;
    }

    public aux ᐝ() throws IOException {
        if (this.ᐝ != null) {
            if (this.ˋॱ) {
                ʻ();
            } else {
                this.ᐝ = null;
                return this;
            }
        }
        ˋॱ();
        this.ˋ.write(HwAccountConstants.NULL);
        return this;
    }

    public aux ˊ(boolean z) throws IOException {
        ʻ();
        ˋॱ();
        this.ˋ.write(z ? "true" : "false");
        return this;
    }

    public aux ˏ(Boolean bool) throws IOException {
        if (bool == null) {
            return ᐝ();
        }
        ʻ();
        ˋॱ();
        this.ˋ.write(bool.booleanValue() ? "true" : "false");
        return this;
    }

    public aux ˏ(long j) throws IOException {
        ʻ();
        ˋॱ();
        this.ˋ.write(Long.toString(j));
        return this;
    }

    public aux ˏ(Number number) throws IOException {
        if (number == null) {
            return ᐝ();
        }
        ʻ();
        CharSequence obj = number.toString();
        if (this.ʽ || !(obj.equals("-Infinity") || obj.equals("Infinity") || obj.equals("NaN"))) {
            ˋॱ();
            this.ˋ.append(obj);
            return this;
        }
        throw new IllegalArgumentException("Numeric values must be finite, but was " + number);
    }

    public void flush() throws IOException {
        if (this.ˊ == 0) {
            throw new IllegalStateException("JsonWriter is closed.");
        }
        this.ˋ.flush();
    }

    public void close() throws IOException {
        this.ˋ.close();
        int i = this.ˊ;
        if (i > 1 || (i == 1 && this.ˎ[i - 1] != 7)) {
            throw new IOException("Incomplete document");
        }
        this.ˊ = 0;
    }

    private void ˏ(String str) throws IOException {
        int i = 0;
        String[] strArr = this.ʻ ? ॱ : ˏ;
        this.ˋ.write("\"");
        int length = str.length();
        for (int i2 = 0; i2 < length; i2++) {
            char charAt = str.charAt(i2);
            String str2;
            if (charAt < '') {
                str2 = strArr[charAt];
                if (str2 == null) {
                }
                if (i < i2) {
                    this.ˋ.write(str, i, i2 - i);
                }
                this.ˋ.write(str2);
                i = i2 + 1;
            } else {
                if (charAt == ' ') {
                    str2 = "\\u2028";
                } else if (charAt == ' ') {
                    str2 = "\\u2029";
                }
                if (i < i2) {
                    this.ˋ.write(str, i, i2 - i);
                }
                this.ˋ.write(str2);
                i = i2 + 1;
            }
        }
        if (i < length) {
            this.ˋ.write(str, i, length - i);
        }
        this.ˋ.write("\"");
    }

    private void ॱˊ() throws IOException {
        if (this.ॱॱ != null) {
            this.ˋ.write("\n");
            int i = this.ˊ;
            for (int i2 = 1; i2 < i; i2++) {
                this.ˋ.write(this.ॱॱ);
            }
        }
    }

    private void ˊॱ() throws IOException {
        int ˋ = ˋ();
        if (ˋ == 5) {
            this.ˋ.write(44);
        } else if (ˋ != 3) {
            throw new IllegalStateException("Nesting problem.");
        }
        ॱˊ();
        ˊ(4);
    }

    private void ˋॱ() throws IOException {
        switch (ˋ()) {
            case 1:
                ˊ(2);
                ॱˊ();
                return;
            case 2:
                this.ˋ.append(',');
                ॱˊ();
                return;
            case 4:
                this.ˋ.append(this.ʼ);
                ˊ(5);
                return;
            case 6:
                break;
            case 7:
                if (!this.ʽ) {
                    throw new IllegalStateException("JSON must have only one top-level value.");
                }
                break;
            default:
                throw new IllegalStateException("Nesting problem.");
        }
        ˊ(7);
    }
}
